# scripts/test03_employee.py IHRM0303測試用例腳本
"""
定義接口測試用例
使用 unittest
1.導包
2.創建測試類
    前置方法
    後置方法
    測試方法
"""

# 導包
import requests
import unittest

import app
from api.employee import EmployeeAPI
from api.login import LoginAPI
# from parameterized import parameterized
from utils import common_assert

# 創建測試類


class TestEmployee(unittest.TestCase):
    # 定義一個這個類的參數 employee_id,用來傳送參數給其他員工管理用例,如:修改員工,查詢員工及刪除員工使用
    employee_id = None
    # employee_id = 1499845280168796160
    # 前置方法
    def setUp(self):
        # 實例化接口類對象 employee_api
        self.employee_api = EmployeeAPI()

    # 後置方法(無)

    # 測試方法
    # 定义测试用例
    # 添加員工測試用例
    def test01_add_employee(self):
        add_employee_data = {
            "username": "vincent9t0745",  # 用户名唯一
            "mobile": "13212072845",  # 手机号唯一
            "timeOfEntry": "2020-07-09",
            "formOfEmployment": 1,
            "workNumber": "011145",  # 员工ID唯一性
            "departmentName": "销售",
            "departmentId": "1266699057968001024",
            "correctionTime": "2020-07-30T16:00:00.000Z"
        }
        response = self.employee_api.add_employee(add_employee_data=add_employee_data)
        print(response.json())
        # 斷言
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(True, response.json().get("success"))
        # self.assertEqual(10000, response.json().get("code"))
        # self.assertIn("操作成功", response.json().get("message"))
        # common_assert(self, response, 200, True, 10000, "操作成功")
        common_assert(self, response)

        # 獲取員工ID
        TestEmployee.employee_id = response.json().get("data").get("id")
        print(TestEmployee.employee_id)

    # 修改員工測試用例
    def test02_update_employee(self):
        update_employee_data = {"username":"rose0702"}
        response = self.employee_api.update_employee(TestEmployee.employee_id, update_employee_data=update_employee_data)
        print(response.json())
        # 斷言
        # common_assert(self, response, 200, True, 10000, "操作成功")
        common_assert(self, response)

    # 查詢員工測試用例
    def test03_get_employee(self):
        response = self.employee_api.get_employee(TestEmployee.employee_id)
        print(response.json())
        # 斷言
        # common_assert(self, response, 200, True, 10000, "操作成功")
        common_assert(self, response)

# 刪除員工測試用例
    def test04_delete_employee(self):
        response = self.employee_api.delete_employee(TestEmployee.employee_id)
        print(response.json())
        # 斷言
        # common_assert(self, response, 200, True, 10000, "操作成功")
        common_assert(self, response)




